const mongoose = require('mongoose')

const Schema = mongoose.Schema

mongoose.connect('mongodb://localhost/test')

const memberSchema = new Schema({
	name : {
		type:String,
		required:true
	},
	password:{
		type:String,
		required:true
	},
	email:{
		type:String
	}
})

var Member = mongoose.model('Member', memberSchema)

// var add_arr = ['周杰伦555', '张学友666', '刘德华666', '周星驰666', '成龙6']
// var add_arr2 = ['zjl141@qq.com', 'zxy144@qq.com', 'ldh44@qq.com', 'zxc16@qq.com', 'cl16@qq.com']
// for (var i = 0; i < 5; i++) {
// 	new Member({
// 		name:add_arr[i],
// 		password:'a' + i,
// 		email:add_arr2[i]
// 	}).save().then(()=>console.log('ok'))
// 	// console.log(add_arr[i],add_arr2[i])
// }
// console.log('begin')

// 新增
// new Member({
// 	name : '董事长',
// 	password : '111111',
// 	email : 'dsz@111111.com'
// }).save()
// 	.then(() => console.log('ok'), (err) => console.log('err'))


// 查询
// Member.find().then((data) => console.log(data))


// Member.find({
// 	name:'董事长'
// }).then((data) => console.log(data))

// Member.findOne({
// 	name : '总经理'
// }).then((data)=>console.log(data))


// 更新
Member.findByIdAndUpdate('5af6e79620f0263eec6e5bc2', {
	password:'cla4',
	email:'cla4@qq.com'
}).then(()=>console.log('更新成功'))